package cn.lngaosu.lwyd.module.integration.controller.admin.weibocommentsshow;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.lngaosu.lwyd.framework.common.pojo.PageParam;
import cn.lngaosu.lwyd.framework.common.pojo.PageResult;
import cn.lngaosu.lwyd.framework.common.pojo.CommonResult;
import cn.lngaosu.lwyd.framework.common.util.object.BeanUtils;
import static cn.lngaosu.lwyd.framework.common.pojo.CommonResult.success;

import cn.lngaosu.lwyd.framework.excel.core.util.ExcelUtils;

import cn.lngaosu.lwyd.framework.apilog.core.annotation.ApiAccessLog;
import static cn.lngaosu.lwyd.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.lngaosu.lwyd.module.integration.controller.admin.weibocommentsshow.vo.*;
import cn.lngaosu.lwyd.module.integration.dal.dataobject.weibocommentsshow.WeiboCommentsShowDO;
import cn.lngaosu.lwyd.module.integration.service.weibocommentsshow.WeiboCommentsShowService;

@Tag(name = "管理后台 - 微博评论")
@RestController
@RequestMapping("/integration/weibo-comments-show")
@Validated
public class WeiboCommentsShowController {

    @Resource
    private WeiboCommentsShowService weiboCommentsShowService;

    @PostMapping("/create")
    @Operation(summary = "创建微博评论")
    @PreAuthorize("@ss.hasPermission('integration:weibo-comments-show:create')")
    public CommonResult<Long> createWeiboCommentsShow(@Valid @RequestBody WeiboCommentsShowSaveReqVO createReqVO) {
        return success(weiboCommentsShowService.createWeiboCommentsShow(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新微博评论")
    @PreAuthorize("@ss.hasPermission('integration:weibo-comments-show:update')")
    public CommonResult<Boolean> updateWeiboCommentsShow(@Valid @RequestBody WeiboCommentsShowSaveReqVO updateReqVO) {
        weiboCommentsShowService.updateWeiboCommentsShow(updateReqVO);
        return success(true);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除微博评论")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('integration:weibo-comments-show:delete')")
    public CommonResult<Boolean> deleteWeiboCommentsShow(@RequestParam("id") Long id) {
        weiboCommentsShowService.deleteWeiboCommentsShow(id);
        return success(true);
    }

    @GetMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除微博评论")
                @PreAuthorize("@ss.hasPermission('integration:weibo-comments-show:delete')")
    public CommonResult<Boolean> deleteWeiboCommentsShowList(@RequestParam("ids") List<Long> ids) {
        weiboCommentsShowService.deleteWeiboCommentsShowListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得微博评论")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('integration:weibo-comments-show:query')")
    public CommonResult<WeiboCommentsShowRespVO> getWeiboCommentsShow(@RequestParam("id") Long id) {
        WeiboCommentsShowDO weiboCommentsShow = weiboCommentsShowService.getWeiboCommentsShow(id);
        return success(BeanUtils.toBean(weiboCommentsShow, WeiboCommentsShowRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得微博评论分页")
    @PreAuthorize("@ss.hasPermission('integration:weibo-comments-show:query')")
    public CommonResult<PageResult<WeiboCommentsShowRespVO>> getWeiboCommentsShowPage(@Valid WeiboCommentsShowPageReqVO pageReqVO) {
        PageResult<WeiboCommentsShowDO> pageResult = weiboCommentsShowService.getWeiboCommentsShowPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WeiboCommentsShowRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出微博评论 Excel")
    @PreAuthorize("@ss.hasPermission('integration:weibo-comments-show:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportWeiboCommentsShowExcel(@Valid WeiboCommentsShowPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<WeiboCommentsShowDO> list = weiboCommentsShowService.getWeiboCommentsShowPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "微博评论.xls", "数据", WeiboCommentsShowRespVO.class,
                        BeanUtils.toBean(list, WeiboCommentsShowRespVO.class));
    }

}